/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2022 All Rights Reserved.
 */
package com.yuanmeng.common.core.enums;

import com.yuanmeng.common.core.exception.ServiceException;
import lombok.Getter;

/**
 * @author outsider
 * @version Id: StatusEnum.java, v 0.1 2022/6/1 17:16 outsider Exp $$
 */
@Getter
public enum TransactionChannelEnum {
    WECHAT("WECHAT", "微信"),

    ALIPAY("ALIPAY", "支付宝"),

    BALANCE("BALANCE", "余额"),

    CARD("CARD", "电子卡"),

    BUYER("BUYER", "采买");

    private String code;

    private String message;

    TransactionChannelEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static void validateTransactionChannel(String transactionChannel) {
        int num = 0;
        for(TransactionChannelEnum ENUM : TransactionChannelEnum.values()) {
            if(ENUM.code.equals(transactionChannel)) {
                num ++;
            }
        }
        if(num == 0) {
            throw new ServiceException("请求参数非法：acceptType");
        }
    }

    public static String codeQueryValue(String transactionChannel) {
        for(TransactionChannelEnum ENUM : TransactionChannelEnum.values()) {
            if(ENUM.code.equals(transactionChannel)) {
                return ENUM.getMessage();
            }
        }
        return "";
    }

    public static String valueQueryCode(String transactionChannelValue) {
        for(TransactionChannelEnum ENUM : TransactionChannelEnum.values()) {
            if(ENUM.message.equals(transactionChannelValue)) {
                return ENUM.getCode();
            }
        }
        return "";
    }
}